/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Server;

import CLIENT.Client;
import Server.ServerMainChatPanel;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;

/**
 *
 * @author Yaniv Kalif
 */
public class NewClientsListenerThread implements Runnable
{
    ServerSocket socket = null;
    ServerMainChatPanel _creatorPanel;
    int _Connected=0;
	public NewClientsListenerThread(ServerSocket socket,ServerMainChatPanel creatorPanel)
	{
		this.socket = socket;
                _creatorPanel=creatorPanel;
	}
        public void run()
        {
            while(_Connected<100) // MAX USERS 100
            {
                try
                {
                    Socket s = socket.accept();//waiting for a new client
                    Client c = new Client(String.valueOf(_Connected),s);
                    _creatorPanel.AddClient(c);//add a new client to the ServerPanel
                    ServerMessageListener msglistener = new ServerMessageListener(c, _creatorPanel);
                    Thread T=new Thread(msglistener);
                    T.start();
                    _Connected++;
                }
                catch (IOException ex)
                {
                    Logger.getLogger(NewClientsListenerThread.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
}
